﻿Public Class frmGratificaciones
    Dim Grati As New clsGratificaciones
    Dim Bitacora As New clsActividad
    Private Sub frmGratificaciones_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolStrip2.Cursor = Cursors.Hand
        ToolStrip2.RenderMode = System.Windows.Forms.ToolStripRenderMode.System
        ToolStrip2.Stretch = True

        If EmpleadoID = 0 Then
            LimpiarCampos()
        Else
            LimpiarCampos()
            Me.txtID.Text = EmpleadoID
            Me.txtNomEmp.Text = frmModuloEmpleadosDetalle.txtPaterno.Text.Trim & " " & frmModuloEmpleadosDetalle.txtMaterno.Text.Trim & " " & frmModuloEmpleadosDetalle.txtNombre.Text.Trim
            Me.txtDepto.Text = frmModuloEmpleadosDetalle.txtDepartamento.Text

        End If
    End Sub
    Sub LimpiarCampos()
        Me.txtCausa.Clear()
        Me.txtDepto.Clear()
        Me.txtID.Clear()
        Me.txtMonto.Clear()
        Me.txtNomEmp.Clear()
        Me.lstTipo.Text = ""
    End Sub
    Private Sub gatter()
        Grati.idGratificacion = (BuscarIntDatoCitra("SELECT MAX(IdGratificacion) as Id FROM Gratificaciones")) + 1
        Grati.IdEmpleado = Me.txtID.Text
        Grati.Departamento = Me.txtDepto.Text
        Grati.Tipo = Me.lstTipo.Text
        Grati.Monto = Me.txtMonto.Text
        Grati.Motivo = Me.txtCausa.Text
        Grati.Usuario = usuarioactivo.Trim
        Grati.Fecha = Me.datfecha.Value
        Grati.Notificado = "No"
        Grati.TipoHora = lstMontoHoras.Text.Trim


    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim lerror As Integer
        lerror = fDespliegaCatalogos(5)
        If frmCatalogos.DialogResult = Windows.Forms.DialogResult.OK Then
            strResult = frmCatalogos.Valor
            Me.txtNomEmp.Text = Trim(frmCatalogos.dgCatalogos.Rows(strResult - 1).Cells(2).Value.ToString())
            Me.txtID.Text = Trim(frmCatalogos.dgCatalogos.Rows(strResult - 1).Cells(1).Value.ToString())
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim lerror As Integer
        lerror = fDespliegaCatalogos(1)
        If frmCatalogos.DialogResult = Windows.Forms.DialogResult.OK Then
            strResult = frmCatalogos.Valor
            Me.txtDepto.Text = Trim(frmCatalogos.dgCatalogos.Rows(strResult - 1).Cells(2).Value.ToString())
        End If
    End Sub

    Private Sub lstTipo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstTipo.SelectedIndexChanged
        If Me.lstTipo.Text = "" Then
            Me.txtMonto.Enabled = False
            Me.lblMonto.Visible = False
            lstMontoHoras.Visible = False

        ElseIf Me.lstTipo.Text = "Horas Extras" Then
            Me.txtMonto.Enabled = True
            Me.lblMonto.Text = "Horas Extras"
            Me.lblMonto.Visible = True
            lstMontoHoras.Visible = True

        ElseIf Me.lstTipo.Text = "Gratificación" Then
            Me.txtMonto.Enabled = True
            Me.lblMonto.Text = "Gratificación"
            Me.lblMonto.Visible = True
            lstMontoHoras.Visible = False
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub

    Private Sub toolGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub toolSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub ToolStripButton5_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton5.Click
        If Me.txtID.Text = "" Then
            MsgBox("Debes indicar un empleado", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtDepto.Text = "" Then
            MsgBox("Debes indicar un departamento", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.lstTipo.Text = "" Then
            MsgBox("Debes indicar el tipo", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtCausa.Text = "" Then
            MsgBox("Debes indicar una justificación para el pago", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtMonto.Text = "" Then
            Me.txtMonto.Text = 0
        End If

        If Me.txtMonto.Text = 0 Then
            MsgBox("Debes indicar una cantidad", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.lstTipo.Text <> "" Then
            If lstTipo.Text = "Horas Extras" Then
                If Me.lstMontoHoras.Text = "" Then
                    MsgBox("Debes indicar el tipo de pago de horas extras", MsgBoxStyle.Exclamation, "Aviso")
                    Exit Sub
                End If
            End If
        End If

        gatter()
        Grati.Insertar()

        'Registra actividad
        Bitacora.RegistraActividad("Registró gratificaciones/horas extras a " & txtNomEmp.Text.Trim)

        LimpiarCampos()
      
            frmModuloEmpleadosDetalle.cargagratificaciones()
            Me.Close()

    End Sub

    Private Sub ToolStripButton1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.Click
        Close()

    End Sub
End Class